home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / mkmf.prog / mkmf < prev   
Encoding:
Text File  |  1992-11-25  |  6.5 KB  |  289 lines

  1. #! /sprite/cmds/csh -f
  2. # Script to generate a Makefile, depending on the current directory.
  3. #
  4. # $Header: /sprite/src/cmds/mkmf.prog/RCS/mkmf,v 1.16 91/11/03 17:42:51 jhh Exp $
  5. #
  6. # The old way to prevent mkmf from working in a directory is
  7. # to have the comment
  8. #    # No mkmf
  9. # in Makefile.  This is being reversed to require a line of the form
  10. #    # Allow mkmf
  11. # before mkmf will run.
  12. #
  13.  
  14. #
  15. # First, make sure "." is not in the path!  Otherwise things like "sed"
  16. # can get screwed up when made in the corresponding sprite directory.
  17. #
  18. set path = (/sprite/cmds.$MACHINE /sprite/cmds)
  19. setenv MKMFDIR /sprite/lib/mkmf
  20. set dependall="pmake dependall"
  21. set depend="pmake depend"
  22. set userMap=()
  23. set sysMap=${MKMFDIR}/mkmf.map
  24. set defmachine=$MACHINE
  25. set distMap=${MKMFDIR}/mkmf.dist
  26. set machTypes=`grep -v "^#" /sprite/admin/machineTypes`
  27.  
  28. #
  29. # No global flags by default.
  30. #
  31. setenv MKMFFLAGS
  32.  
  33. #
  34. # If makeRCS is set, an RCS directory will be created should one not exist
  35. # If makeMd is set, a machine-dependent subdirectory will be created if
  36. # none exists already.
  37. #
  38. set makeRCS
  39. set makeMd
  40.  
  41. #
  42. # Process options.
  43. #
  44. set i=1
  45. set makefile=Makefile
  46. set machinesToDo
  47. set noglob
  48. set usage = 'Usage: mkmf [-x] [-f file] [-mtm | -m tm]'
  49. unset noglob
  50.  
  51.  
  52. while ( $i <= $#argv )
  53.     switch( "$argv[$i]" )
  54. #
  55. # Handle echoing
  56. #
  57.         case "-x" 
  58.             set echo
  59.             setenv MKMFFLAGS "$MKMFFLAGS -x"
  60.             shift
  61.             @ i--
  62.             breaksw
  63. #
  64. # Figure out alternate makefile if -f given
  65. #
  66.         case "-f" :
  67.             if ($i != $#argv) then
  68.                 shift
  69.                 set makefile=$argv[$i]
  70.                 shift
  71.                 @ i--
  72.             endif
  73.             breaksw
  74. #
  75. # Build list of machine types to be done.
  76. #
  77.         case "-m*" :
  78.             set tmp = `echo "$argv[$i]" | sed "s/-m//"`
  79.             if ("$tmp" == '') then
  80.                 if ($i != $#argv) then
  81.                 shift
  82.                 set machinesToDo = ($machinesToDo $argv[$i])
  83.                 unset dependall
  84.                 shift
  85.                 else
  86.                 echo "$usage"
  87.                 exit (1)
  88.                 endif
  89.             else
  90.                 set machinesToDo = ($machinesToDo $tmp)
  91.                 unset dependall
  92.                 shift
  93.             endif
  94.             @ i--
  95.             breaksw
  96.         default :
  97.             echo "$usage"
  98.             exit(1)
  99.             breaksw
  100.     endsw
  101.     @ i++
  102. end
  103.  
  104. #
  105. # If the caller has a .mkmf file in his/her home directory, source it
  106. # now;  this can be used to modify some of the controlling variables
  107. # above, like MKMFDIR and map.
  108. #
  109.  
  110. if (-e ~/.mkmf) then
  111.     source ~/.mkmf
  112. endif
  113.  
  114. #
  115. # Check for permission to do this:
  116. # egrep -s returns 0 if a match is found for the pattern.
  117. # If a "no mkmf" comment is found in the current makefile, we refuse to run.
  118. # If no "allow mkmf" comment is in the current makefile, we must ask permission
  119. # before proceeding (if permission given, save the old Makefile in a
  120. # backup location, just in case).
  121. #
  122. #
  123. if (-e $makefile) then
  124.     if ({ egrep -s '^#[     ]*[Nn]o mkmf' $makefile }) then
  125.         echo "Sorry, mkmf not allowed in this directory"
  126.         exit 1
  127.     else if (! { egrep -s '^#[     ]*[Aa]llow mkmf' \
  128.         $makefile }) then
  129.         echo "WARNING: no '# Allow mkmf' in existing $makefile"
  130.         echo -n "Ok to run mkmf? Enter 'y' if ok: "
  131.         set a="$<"
  132.         if ("$a" !~ [Yy]*) then
  133.             echo "mkmf aborted"
  134.             exit 1
  135.         endif
  136.         mv -f $makefile $makefile.~
  137.     endif
  138. endif
  139.  
  140. #
  141. # Determine what version of mkmf to run. Set $mkmf to contain that version name
  142. # Pass through mkmf.map looking for a line whose pattern matches the
  143. # current working directory and place the following fields into
  144. # 'ans'.
  145. #
  146.  
  147. set ans=()
  148. if ( "$userMap" != "") set ans=(`echo $cwd | awk -f $userMap`)
  149. if ( "$ans" == "")     set ans=(`echo $cwd | awk -f $sysMap`)
  150. set distdir=()
  151. if ( "$distMap" != "") set distdir=(`echo $cwd | nawk -f $distMap`)
  152. set mkmf=$ans[1]
  153. if ($ans[2] !~ [Yy]*) unset makeRCS
  154. if ($ans[3] !~ [Yy]*) then
  155.     unset depend
  156.     unset dependall
  157. endif
  158. if ($ans[4] !~ [Yy]*) unset makeMd
  159. setenv DISTDIR $distdir
  160. setenv SUBTYPE $ans[5]
  161. #
  162. # This is a kludge because the machine types "sun4c" and "ds5000" are
  163. # only visible in the kernel sources.
  164. #
  165. if ($ans[5] == "kernel") then
  166.     set machTypes=($machTypes "sun4c" "ds5000")
  167. endif
  168.  
  169. setenv MKMF ${MKMFDIR}/mkmf.$mkmf
  170. if (-x mkmf.local && ! -d mkmf.local) then
  171.     echo "Using mkmf.local"
  172.     set uselocal
  173. endif
  174.  
  175. #
  176. # Create RCS directory if it should be here but isn't
  177. #
  178. if ((! -e RCS) && $?makeRCS) then
  179.     echo "Making RCS directory."
  180.     mkdir RCS
  181. endif
  182.  
  183. #
  184. # Create ".md" directories (if they don't already exist) for those
  185. # machine types specified with the "-m" option.  Also check that the
  186. # machine types are valid.
  187. #
  188. if ("$machinesToDo" != "") then
  189.     set tmp=""
  190.     foreach i ($machinesToDo)
  191.     if (! -e $i.md) then
  192.         if (" $machTypes " =~ *\ $i\ *) then
  193.         echo "Making $i.md directory."
  194.         mkdir $i.md
  195.         chmod 775 $i.md
  196.         set tmp=($tmp $i)
  197.         else 
  198.         echo "$i isn't a valid machine type."
  199.         endif
  200.     else
  201.         set tmp=($tmp $i)
  202.     endif
  203.     end
  204.     if ("$tmp" == "") then
  205.     exit 1
  206.     else
  207.     set machinesToDo=($tmp)
  208.     endif
  209. endif
  210.  
  211. #
  212. # Locate machine-dependent subdirectories (*.md) and set the environment
  213. # variable MACHINES to hold the names of the machines that we are to run
  214. # mkmf for, and ALLMACHINES to the names of all possible machine
  215. # types (without the ".md"suffixes).  
  216. # If no machine-dependent subdirectories exist, create one
  217. # if that's permitted.
  218. #
  219. set nonomatch
  220. set mds=(*.md)
  221. unset nonomatch
  222. set machines
  223. set domachines
  224. if ("$mds" != "*.md") then
  225.     foreach i ($mds)
  226.         set machName =  $i:r
  227.         if ("$machinesToDo" == "" || \
  228.             " $machinesToDo " =~ *\ $machName\ *) then
  229.             set domachines = ($domachines $machName)
  230.         endif
  231.         set machines = ($machines $machName)
  232.     end
  233. else
  234.     if ( $?makeMd ) then
  235.         echo "Making $defmachine.md directory."
  236.         mkdir $defmachine.md
  237.         if ("$machinesToDo" == "" || \
  238.             " $machinesToDo " =~ *\ $defmachine\ *) then
  239.             set machines=($defmachine)
  240.             set domachines=($defmachine)
  241.         endif
  242.     endif
  243. endif
  244. setenv MACHINES "$machines"
  245. setenv DOMACHINES "$domachines"
  246.  
  247. #
  248. # Store the name of the makefile we're manipulating in the MAKEFILE
  249. # envariable and invoke the appropriate version of mkmf
  250. #
  251. setenv MAKEFILE $makefile
  252. if ($?uselocal) then
  253.     eval ./mkmf.local $MKMFFLAGS $*
  254. else
  255.     eval ${MKMFDIR}/mkmf.$mkmf $MKMFFLAGS $*
  256. endif
  257.  
  258. #
  259. # if a .sed file exists for the makefile, muck with it some more
  260. #
  261. if (-e $makefile.sed) then
  262.     echo "Modifying with $makefile.sed."
  263.     mv $makefile{,.$$~~}
  264.     sed -f $makefile.sed $makefile.$$~~ > $makefile
  265.     rm $makefile.$$~~
  266. endif
  267.  
  268. #
  269. # if a .ex file exists for the makefile, edit the makefile using the .ex file
  270. # as a command script
  271. #
  272. if (-e $makefile.ex) then
  273.     echo "Modifying with $makefile.ex."
  274.     ex - $makefile < $makefile.ex
  275. endif
  276.  
  277. #
  278. # Form dependencies for the makefile if required
  279. #
  280. if ($?dependall) then
  281.     eval $dependall
  282. else if ($?depend) then
  283.     foreach i ($domachines)
  284.         eval $depend TM=$i
  285.     end
  286. endif
  287.  
  288. exit 0
  289.